import path from "path";

export function generateTree(routes, checkedKeys, basePath = "/") {
  const res = [];
  for (const route of routes) {
    const routePath = path.resolve(basePath, route.path);
    // recursive child routes
    if (route.children) {
      route.children = generateTree(route.children, checkedKeys, routePath);
    }

    if (
      checkedKeys.some(item => {
        if (item.path === routePath) {
          route.meta = item.meta
          route.menuId = item.menuId
          return true
        }
      }) ||
      (route.children && route.children.length >= 1)
    ) {
      res.push(route);
    }
  }
  return res;
}

// 为按钮添加权限
const directiveButton = (route, value) => {
  let obj = {}
  obj[route.$route.path] = route.$route.path + '_' + value
  return obj
}

export default {
  directiveButton,
}